package com.utils;


import com.app.util.Utils_Data;
import com.bean.TalkMessage;
import com.bean.TalkMessageDB;
import com.example.com.skills_utf8.ApplicationCustom;
import com.example.com.skills_utf8.R;
import com.lidroid.xutils.DbUtils;
import com.lidroid.xutils.db.sqlite.WhereBuilder;
import com.lidroid.xutils.exception.DbException;

import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

public class g {

	public static boolean DEBUG = false;
	public static boolean RELEASE = !DEBUG;
	
	public static boolean NET_SHOPPING_CAR = false;
	public static boolean LOCAL_SHOPPING_CAR = !NET_SHOPPING_CAR;
	
	
	public static String DB_PATH =""; // 在provider中动态得到
	
	
	public static boolean X_INSIDE = true;
	
	
	
	public static boolean THIRD_PARTY = false;
	public static boolean THIRD_PARTY_QQ = false;
	

	public static boolean use_network = false; //是否强制使用网络来定位
	public static boolean bSendError = false; // 为true将不再使用邮箱







	// 阿里云服务器
	public static String SERVER_PAY_HOST = "http://192.168.82.11/"; //"http://192.168.1.107/"; //"http://121.40.92.244:11088/"; //
	public class SERVER_PAY_API
	{
		public static final String sendsms = "common/sendsms.php/sendsms.php";

		public static final String log_post = "php_bbpos/api.php/fuc/log";
		public static final String umeng_message_regist = "php_bbpos/api.php/umeng/umeng_message_regist";

		public static final String umeng_message_all = "php_bbpos/api.php/umeng/umeng_message_select";
		public static final String umeng_message_send = "php_bbpos/api.php/umeng/umeng_message_send";


		//
		public static final String register = "php_bbpos/api.php/app/register";
		public static final String login = "php_bbpos/api.php/app/login";
		public static final String select = "php_bbpos/api.php/app/select";
		public static final String updateaudio = "php_bbpos/api.php/app/updateaudio";


		//显示百度地图
		public static final String baidumapdisplay = "php_bbpos/api.php/baidu/display";


		public static final String updateaudio_jpush = "php_bbpos/api.php/app/updateaudio_jpush";
	}


	//--
	public static String id_umeng = "";
	public static String id_user = getPhoneNO() + getPhoneModel();
	public static String token = "";


	public static String umeng_app_key = "5511252cfd98c54de5000996";
	public static String umeng_app_key_secret = "a3751ac91ade4a164aff5117a896ed10";

	//--
	public static String qiniu_ak = "e1kEu5dhcwThWDrkc1-FrmKQAz0uQ55paVbK6zdP";
	public static String qiniu_sk = "w5njHcH-jMkaaKiGhJ1OcqGYuNN8upkSAAo7RwMp";


	public static String id_jpush = "";




	public static String getPhoneModel(){

		return android.os.Build.MODEL + ","
				+ android.os.Build.VERSION.RELEASE;

	}
	public static String getPhoneNO() {

		return "";
	}
	//



	public static Map<String, Object> imjo = new HashMap<>();
	static{
		// 加载表情包
		imjo.put("#smile#", R.drawable.f001);
		imjo.put("#sad#", R.drawable.f002);

	}

	public static String imjo_find(Integer o){

		for (Map.Entry<String, Object> entry : imjo.entrySet()) {
			int value = (int)entry.getValue();
			if(value == o){
				return entry.getKey();
			}

		}

		return "";

	}

	public static int imjo_find(String str){

		for (Map.Entry<String, Object> entry : imjo.entrySet()) {
			if(str.equals(entry.getKey())){
				return (int)entry.getValue();
			}

		}

		return 0;

	}

	public static String imjo_key(){
		String key = "";

		for (Map.Entry<String, Object> entry : imjo.entrySet()) {
			key += entry.getKey() + "|";
		}

		if(!key.isEmpty()){
			key = key.substring(0, key.length()-1);
		}

		return key;
	}


	public static class Intent{
		public static String ACTION_MSG_RECIVE = "msg_recive";
		public static String ACTION_MSG_COME = "msg_come";
	}



	public static void Save2DB(DbUtils db, TalkMessage message){

		// 保存到数据库
		try {
			String content = GsonParse.parse(message);

			TalkMessageDB messagedb = new TalkMessageDB();
			messagedb.setId_device(message.getId_umeng());
			messagedb.setContent(content);
			messagedb.setContent_md5(Utils_Data.MD5(content));
			db.saveBindingId(messagedb);

		} catch (DbException e) {
			e.printStackTrace();
		}


	}

	public static void update2DB(DbUtils db, String md5, TalkMessage message){

		// 保存到数据库
		try {

			String content = GsonParse.parse(message);

			TalkMessageDB messagedb = new TalkMessageDB();
			messagedb.setId_device(message.getId_umeng());
			messagedb.setContent(content);
			messagedb.setContent_md5(Utils_Data.MD5(content)); // 更新md5

			db.update(messagedb, WhereBuilder.b("content_md5", "=", md5) );

		} catch (DbException e) {
			e.printStackTrace();
		}


	}


	 
	/*
	public static void showSimpleAlertDialog(Activity activity, String title, String messsage,
			String btnName) {
		
		new AlertDialog.Builder(activity)
				.setTitle(title)
				.setMessage(messsage)
				.setPositiveButton(btnName,
						new DialogInterface.OnClickListener() {
							@Override
							public void onClick(DialogInterface dialog,
									int which) {
								// TODO Auto-generated method stub
								dialog.dismiss();
							}
						}).create().show();

	}
	*/
	
	/*
	public static boolean isNetBackSucess2(String message){
		
		String[] array =message.split("\\|");
		if(array == null || array.length < 2) // 或者长度不够
			return false;
		
		String backResult =array[0];
		String content=array[1];
		if(backResult.equals("0")){	
	//		Utils.showToastShort(activity, content);
			return true;
		}
		else
			return false;
		
		
	}
	
	
	public static boolean isNetBackSucess3( String message){
		
		
		
		String[] array =message.split("\\|");
		if(array == null || array.length < 3) // 或者长度不够
			return false;
		
		String backResult =array[0];
		String content=array[1];
		String value =array[2];
		if(backResult.equals("0")){	
		//	Utils.showToastShort(activity, content);
			return true;
		}
		else  // 这里判断2或者4, 重新登陆呢?
			return false;
	
		
	}
	
	*/
	
	
	/*
		
		String[] array =message.split("\\|");
		if(array == null || array.length < 3) // 或者长度不够
			return;
		
		String backResult = array[0];
		String content=array[1];
		String value =array[2];
		if(backResult.substring(0,1).equals("0")){
			
			Utils.showToastShort(activity, "上传成功");
		}
	 */
	
	
}
